# coding: utf-8
# @Author: cyl
# @File: conftest.py
# @Time: 2024/09/25 21:32:38
import time
import pytest


def pytest_collection_modifyitems(items):
  """测试用例收集完成后, 将item.name和item.nodeid的中文显示在控制台"""
  for item in items:
    item.name = item.name.encode("utf-8").decode("unicode_escape")
    item.node_id = item.nodeid.encode("utf-8").decode("unicode_escape")


@pytest.fixture(scope="session", autouse=True)
def fix_session():
    print("---session---")


def pytest_terminal_summary(terminalreporter, exitstatus, config):
    """收集测试结果"""
    print(terminalreporter.stats)
    print("total:", terminalreporter._numcollected)
    print('passed:', len([i for i in terminalreporter.stats.get('passed', []) if i.when != 'teardown']))
    print('failed:', len([i for i in terminalreporter.stats.get('failed', []) if i.when != 'teardown']))
    print('error:', len([i for i in terminalreporter.stats.get('error', []) if i.when != 'teardown']))
    print('skipped:', len([i for i in terminalreporter.stats.get('skipped', []) if i.when != 'teardown']))

    # terminalreporter._sessionstarttime 会话开始时间
    duration = time.time() - terminalreporter._sessionstarttime
    print('total times:', duration, 'seconds')
